package com.jsean.core.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.openhft.chronicle.queue.ChronicleQueue;
import net.openhft.chronicle.queue.ExcerptAppender;

public class LogProducer {
    private static final Logger logger = LoggerFactory.getLogger(LogProducer.class);

    public static void main(String[] args) {
        String path = "store";
        logger.info("Starting Producer...");

        try (ChronicleQueue queue = ChronicleQueue.singleBuilder(path).build()) {
            ExcerptAppender appender = queue.createAppender();

            int count = 0;
            while (true) {
                String msg = "Log message #" + (count++);
                appender.writeText(msg);
                logger.debug("Produced: {}", msg);

                try {
                    Thread.sleep(100); // 模拟写入频率
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    logger.warn("Producer interrupted.");
                    break;
                }
            }
        } catch (Exception e) {
            logger.error("Producer error", e);
        }
    }
}